package sqliet

import (
	"github.com/glebarez/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"server/pkg/conf"
)

var DB *gorm.DB

func InitDB(config *conf.Config) (*gorm.DB, error) {
	//config := config.Config

	var gormConfig gorm.Config
	if config.Sql.LogMode { //是否打印SQl语句
		gormConfig.Logger = logger.Default.LogMode(logger.Info)
	}
	gormConfig.DisableForeignKeyConstraintWhenMigrating = true
	// 配置dsn
	db, err := gorm.Open(sqlite.Open("file:./database/test.db?cache=shared&mode=rwc&_journal_mode=WAL"), &gormConfig)

	if err != nil {
		panic("数据库链接错误")
		return db, err
	}
	return db, nil
}
